#include<iostream>

using namespace std;
const int N=1e6+10;
struct node
{
	int p,e;
	int flag[26];
}tree[N];
int index;

void insert(string &s)
{
	int cur=0;
	tree[cur].p++;

	for(auto &e:s)
	{
		int path=e-'a';
		if(tree[cur].flag[path]==0)
		{
			tree[cur].flag[path]=++index;
		}

		cur=tree[cur].flag[path];
		tree[cur].p++;
	}
	tree[cur].e++;
}

int find(string &s)
{
	int cur=0;
	for(auto&e:s)
	{
		int path=e-'a';
		if(tree[cur].flag[path]==0)
		{
			return 0;
		}
		cur=tree[cur].flag[path];
	}

	return tree[cur].e;
}

int find_pre(string &s)
{
	int cur=0;
	for(auto&e:s)
	{
		int path=e-'a';
		if(tree[cur].flag[path]==0) return 0;
		cur=tree[cur].flag[path];
	}
	return tree[cur].p;
}
int main()
{
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		string s;cin>>s;
		insert(s);
	}

	for(int i=1;i<=m;i++)
	{
		string s;cin>>s;
		cout<<"qinazhui:"<<find_pre(s)<<endl;
		cout<<"zifuchuan"<<find(s)<<endl;
	}
}